<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
require_once './_AddinLibraries/database_driver.php';

function get_degree_list() {
    select_itec_database();
    $degrees = array();
    $sql = db_query("SELECT distinct Name FROM degree");
    //$sql = db_query("SELECT distinct degreeid FROM degree");
    while ($erg = $sql->fetchAssoc()) {
        if ($erg == NULL)
            break;
        $degrees[] = $erg['name'];
    };
    select_drupal_database();
    return $degrees;
}

function get_program_list_by_degree($degree) {
    $program = array();
    $headers = header_query('program');
    select_itec_database();
    $sql = db_query("call sp_GetListOfProgramByDegree('".$degree."')");
    $i=0;
    while ($erg = $sql->fetchAssoc()) {
        if ($erg == NULL)
            break;
        foreach($headers as $header){
            $header = strtolower($header);
            $program[$i][$header] = $erg[$header];
        }
        ++$i;
    };
    //drupal_set_message(t('The queries CLASS MEMBER have been made.'));
    select_drupal_database();
    return $program;
}

function add_program($id, $name, $des, $deg){
    select_itec_database();
    $sql = db_query("call sp_AddProgram('".$id."','".$name."','".$des."','".$deg."')");
    $result = $sql->fetchAssoc();
    
    select_drupal_database();
    return $result['result'];
}

function update_program($id, $name, $des, $deg){
    select_itec_database();
    $sql = db_query("call sp_UpdateProgramInfo('".$id."','".$name."','".$des."','".$deg."')");
    $result = $sql->fetchAssoc();
    
    select_drupal_database();
    return $result['result'];
}

function get_program_info_from_id($id) {
    select_itec_database();
    $sql = db_query("call sp_GetProgramInfoFromID('".$id."')");
    $result = $sql->fetchAssoc();
    select_drupal_database();
    
    return $result;
}

?>
